<?php
/**
 * Created by PhpStorm.
 * User: Dream
 * Date: 2017/12/2
 * Time: 16:06
 */

namespace App\Http\Controllers\Index;


use App\Base\BaseFunc;
use Illuminate\Routing\Controller;
use App\Base\OrderStatus;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class OrderController extends Controller
{
    public function order_goods(OrderStatus $orderStatus,BaseFunc $baseFunc)
    {
        $value = Input::only("drug_id",'business_id');
        $input['re_business'] = $value['business_id'];
        $input['re_drug_id'] = $value['drug_id'];
        $input['re_user_drug_status'] = $orderStatus->unOrder()->status_id;
        $input['re_user_drug_time'] = date('Y-m-d H:i:s');
        $input['re_user_id'] = session('user_id');
        DB::table('re_user_drug')->insert($input);
        $baseFunc->setRedirectMessage(true,'预定成功,可到我的预定查看！',NULL,NULL);
        return redirect()->back();
    }

    public function goods_order()
    {
        $data['orderData'] = DB::table('re_user_drug')
            ->leftJoin('drug','drug_id','=','re_drug_id')
            ->leftJoin('status','status_id','=','re_user_drug_status')
            ->where('re_user_id','=',session('user_id'))
            ->get();
        return view("/index.goodsOrder",$data);
    }

    public function re_user_car(BaseFunc $baseFunc,$business_id)
    {
        $input['business_id'] = $business_id;
        $input['user_id'] = session('user_id');
        DB::table('re_user_business')->insert($input);
        $baseFunc->setRedirectMessage(true,'收藏成功,可到我的收藏查看！',NULL,NULL);
        return redirect()->back();
    }

    public function business_car()
    {
        $data['car'] = DB::table('re_user_business')
            ->join('business','business.business_id','=','re_user_business.business_id')
            ->where('user_id','=',session('user_id'))
            ->get();
        return view("/index.goodsCar",$data);
    }
}